package zzc.javaWeb.javaWebHomew.servlet;


import zzc.javaWeb.javaWebHomew.dao.homeDaoimp;
import zzc.javaWeb.javaWebHomew.pojo.UserBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;

@WebServlet("/input")

public class inputMes extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //new
        UserBean userBean=new UserBean();

        req.setCharacterEncoding("utf-8");
        //add
        String  _id= req.getParameter("id");
        String  _keti= req.getParameter("keti");
        String  _yuliang= req.getParameter("yuliang");


        if (_id!=null){
            int id = Integer.parseInt(_id);
            userBean.setId(id);
        }
        if (_keti!=null){
            System.out.println(_keti);
            userBean.setKeti(_keti);
        }
        if (_yuliang!=null){
            int yuliang = Integer.parseInt(_yuliang);
            userBean.setYuliang(yuliang);
        }
        homeDaoimp homeDaoimp = new homeDaoimp();
        try {
            int flag =homeDaoimp.addhomePage(userBean);
            if (flag==1){
              resp.sendRedirect("/Jer/home.jsp");
            }else
            {
               resp.sendRedirect("/Jer/error.html");

            }
        } catch (SQLException throwables) {
            resp.sendRedirect("/Jer/error.html");
            throwables.printStackTrace();
        }


    }
}
